package logic

import (
	"context"
	"fmt"
	"we-chat-reg/model"

	"we-chat-reg/weixinrpc/internal/svc"
	"we-chat-reg/weixinrpc/weixinrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowLogic {
	return &ShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowLogic) Show(in *weixinrpc.ShowRequest) (*weixinrpc.ShowResponse, error) {
	// todo: add your logic here and delete this line

	var WeiChant model.WeiChat
	model.DB.Debug().Where("tel=?", in.Tel).Find(&WeiChant)
	if WeiChant.ID == 0 {
		return nil, fmt.Errorf("该账号未发布朋友圈")
	}

	return &weixinrpc.ShowResponse{
		Img:      WeiChant.Img,
		Username: WeiChant.Username,
		Address:  WeiChant.Address,
		Tel:      WeiChant.Tel,
		Password: WeiChant.Password,
	}, nil
}
